package com.i3nu.contacts.activity;

import com.i3nu.contacts.activity.ContactsListActivity;
import com.i3nu.contacts.db.ContactsProvider;
import com.i3nu.contacts.model.Constants;
import com.i3nu.contacts.model.MyIntent;
import com.i3nu.contacts.activity.R;
import android.app.Activity;
import android.app.TabActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.Toast;

public class DialtactsActivity extends TabActivity implements TabHost.OnTabChangeListener{
    private TabHost tabHost;
    
    private static final int TAB_INDEX_CONTACTS = 0;
    private static final int TAB_INDEX_GROUP = 1;
    private static final int TAB_INDEX_ACTIVITY = 2;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialer_activity);
        
        tabHost=this.getTabHost();
        tabHost.setOnTabChangedListener(this);
        
        this.setupContactsTab();
        this.setupGroupTab();
        this.setupActivityTab();
        
        
        this.setDefaultTab(TAB_INDEX_CONTACTS);
        

    }

    @Override
    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub
        Activity activity = getLocalActivityManager().getActivity(tabId);
        if (activity != null) {
            activity.onWindowFocusChanged(true);
        }
    }
    
    
    private void setupContactsTab() {
        Intent intent = new Intent();
        intent.setClass(this, ContactsListActivity.class);

        tabHost.addTab(tabHost.newTabSpec("contacts")
                .setIndicator(getText(R.string.tab_contacts_list),
                        getResources().getDrawable(R.drawable.ic_tab_contacts))
                .setContent(intent));
    }
    private void setupGroupTab() {
        Intent intent = new Intent(MyIntent.ACTION_GROUP);

        tabHost.addTab(tabHost.newTabSpec("group")
                .setIndicator(getText(R.string.tab_group),
                        getResources().getDrawable(R.drawable.ic_tab_dialer))
                .setContent(intent));
    }
    private void setupActivityTab() {
        Intent intent = new Intent(MyIntent.ACTION_BLOG);

        tabHost.addTab(tabHost.newTabSpec("blog")
                .setIndicator(getText(R.string.tab_blog),
                        getResources().getDrawable(R.drawable.ic_tab_recent))
                .setContent(intent));
    }
    
    
    public void displayToast(String str){
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }
}